<template>
  <div class="main">
    <div class="form_content">
      <NScrollbar>
        <div class="content">
          <div class="topTitle">基本信息</div>
          <NSpace>
            <NForm
              ref="formRef"
              :model="formValue"
              :rules="rules"
              label-placement="left"
              :label-width="160"
              require-mark-placement="left"
              label-align="right"
            >
              <NSpace>
                <NFormItem
                  label="类型:"
                  path="clueName"
                >
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择征集信息"
                    clearable
                    style="width: 210px; margin-right: 20px"
                  />
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择征集信息"
                    clearable
                    style="width: 210px; margin-right: 20px"
                  />
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择征集信息"
                    clearable
                    style="width: 210px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="名称:"
                  path="transferUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入移交人"
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="接收时间:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入移交人"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="征集方式:"
                  path="receiveTime"
                >
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择征集信息"
                    clearable
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="数量:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入移交人"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="接收人:"
                  path="transferUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入接收人"
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="交送单位:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入交送单位"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="移交人联系方式:"
                  path="transferUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入移交人联系方式"
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="移交人:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入移交人"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="督交人:"
                  path="transferUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入督交人"
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="出版时间:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入出版时间"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="定价:"
                  path="transferUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入定价"
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="作者:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入作者"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="版次:"
                  path="transferUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入版次"
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="印次:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入印次"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
              <NSpace>
                <NFormItem
                  label="是否套装书:"
                  path="transferUserId"
                >
                  <NSelect
                    :options="listOption"
                    v-model:value="formValue.provideId"
                    placeholder="请选择是否套装书"
                    clearable
                    style="width: 250px"
                  />
                </NFormItem>
                <NFormItem
                  label="征集备注:"
                  path="receiveUserId"
                >
                  <NInput
                    v-model:value="formValue.transferUserId"
                    placeholder="输入征集备注"
                    style="width: 250px"
                  />
                </NFormItem>
              </NSpace>
            </NForm>
          </NSpace>
          <div class="topTitle">其他信息</div>
          <NSpace>
            <NForm
              ref="formRef"
              :model="formValue"
              :rules="rules"
              label-placement="left"
              :label-width="115"
              label-align="right"
            >
              <NSpace>
                <NFormItem
                  label="附件:"
                  path="fileId"
                >
                  <VUpload
                    :file-list="formValue.fileList"
                    @getList="handleUploadList"
                  />
                </NFormItem>
              </NSpace>
            </NForm>
          </NSpace>
        </div>
      </NScrollbar>
    </div>
  </div>
  <FixedAction>
    <NSpace justify="center">
      <NButton
        style="width: 78px"
        ghost
        @click="goBack"
      >
        取消
      </NButton>
      <NButton
        type="primary"
        style="width: 78px"
        :disabled="loading"
        :loading="loading"
      >
        保存
      </NButton>
    </NSpace>
  </FixedAction>
</template>
<script setup lang="ts">
import { NScrollbar, NButton, NSpace, NForm, NFormItem, NSelect, NInput } from 'naive-ui'
import type { HttpResponse } from '@/utils/http'
import { useRoute } from 'vue-router'
import router from '@/router'
import { ref, watch, reactive } from 'vue'
import { useTagStore } from '@/stores/layout'
import FixedAction from '@/components/FixedAction.vue'
import { sendRequest } from '@/utils/api'
import VUpload from '@/views/OA/Common/Upload.vue'
import { keysOf } from '@/utils/object'

const props = defineProps({
  id: String
})
const rules = {
  clueName: {
    required: true,
    message: '请输入线索名称',
    trigger: 'blur'
  },
  transferUserId: {
    required: true,
    message: '请输入移交人',
    trigger: ['change', 'blur']
  },
  receiveUserId: {
    required: true,
    message: '请输入接收人',
    trigger: 'blur'
  }
}
const formValue = reactive({
  transferUserId: '',
  provideId: '',
  fileIds: '',
  fileList: []
})
const loading = ref(false)
const listOption = ref([])
const route = useRoute()
const tags = useTagStore().tags
// 返回
const goBack = () => {
  const index = tags.findIndex((item: any) => item.path === router.currentRoute.value.fullPath)
  
    tags.splice(index, 1)
if (tags.length == 0) {
    router.push({ path: '/OA/Workbench/UserDesktop' })
  } else history.back()
}
// 附件
const handleUploadList = (v: any) => (formValue.fileIds = v)
//回显
const spinShow = ref(false)
const idT = ref()
const getInfo = async () => {
  idT.value = route.query.id
  spinShow.value = true
  await sendRequest<HttpResponse>({
    module: 'collectNotice',
    api: 'infoProvide',
    override: {
      params: {
        id: idT.value
      }
    }
  }).then(([err, res]) => {
    if (err) return
    keysOf(res.data.examineVo).forEach((e) => {
      {
        // @ts-ignore
        formValue.examineVo[e] = res.data.examineVo[e] as never
      }
    })
    keysOf(res.data.provideVo).forEach((e) => {
      {
        // @ts-ignore
        formValue.provideVo[e] = res.data.provideVo[e] as never
      }
    })
  })
  spinShow.value = false
}

watch(
  () => route,
  () => {
    if (route.name == 'ClueOrganizationDetail') {
      //  getInfo()
    }
  },
  { deep: true, immediate: true }
)
</script>
<style scoped lang="scss">
@mixin CommonFont {
  font-size: 18rem;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  color: #333333;
}

.main {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;

  .form_content {
    width: 100%;
    height: 100%;
    padding: 20rem 20rem 0;

    .topTitle {
      font-size: 22px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      color: #5fb17f;
      margin-bottom: 10rem;
    }

    .content {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 18rem 33rem 120rem;
      overflow-y: scroll;
      background-color: #ebeceb;
      @include CommonFont;

      .basin-info {
        display: flex;
        width: 100%;
        height: auto;
        border-bottom: 1px dashed #bc9e70;
        margin-bottom: 10rem;

        .basin-left {
          flex: 0 0 40%;
        }
        .box {
          display: flex;
          margin-bottom: 20rem;
          font-size: 16rem;

          span:first-child {
            display: inline-block;
            width: 140rem;
          }

          span:last-child {
            display: inline-block;
            flex: 1;
          }
        }

        .box:last-child {
          margin-bottom: 20rem;
        }
      }
      .basin-infoB {
        display: flex;
        width: 100%;
        height: auto;
        margin-bottom: 10rem;

        .basin-left {
          flex: 0 0 40%;
        }
        .box {
          display: flex;
          margin-bottom: 20rem;
          font-size: 16rem;

          span:first-child {
            display: inline-block;
            width: 120rem;
          }

          span:last-child {
            display: inline-block;
            flex: 1;
          }
        }

        .box:last-child {
          margin-bottom: 20rem;
        }
      }
    }
  }
}

.content::-webkit-scrollbar {
  display: none;
}

:deep(.n-spin-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-content) {
  width: 100%;
  height: 100%;
}

:deep(.n-spin-content) {
  width: 100%;
  height: 100%;
}
</style>
